﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvanceLib.ScriptCore;
using AdvanceLib.ScriptCore.DebugCore;

namespace AdvanceLib.Extension.Root.DebugPasses
{
    public class SystemCommandExistsPass : CommandPass
    {
        #region Constructors
        public SystemCommandExistsPass(RootProvider provider)
        {
            this._host = provider.Host;
        }
        #endregion

        #region Fields
        private ScriptHost _host;
        #endregion

        #region IterativeCommandDebugger Members
        public override void Pass(DebugResult result, string input)
        {
            if (this.CurrentLinePartIndex == 0 &&
                this.CurrentLine.StartsWith(this._host.SystemCommandInitialization))
            {
                string commandName = input.Substring(this._host.SystemCommandInitialization.Length);
                if (!this._host.ExtensionManager.HasSystemCommand(commandName))
                {
                    result.Errors.Add(new DebugError()
                    {
                        Line = this.CurrentLineIndex,
                        Message = "Systemcommand '" + commandName + "' does not exist."
                    });
                }
            }
        }
        #endregion
    }
}
